﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace apparatus
{
    public partial class frmlogin : Form
    {
        public frmlogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                this.userTableAdapter1.checkuser(this.db1DataSet1.user, textBox1.Text, textBox2.Text);    
                //初始用户名及密码：aaa aaa或bbb bbb
                if (this.db1DataSet1.user.Count != 0)
                {
                    MessageBox.Show("登录成功！");
                    this.Visible = false;
                    if (this.db1DataSet1.user.Rows[0]["usertype"].ToString() == "admin")//管理员登录
                    {
                        frmadmin frmadmin1 = new frmadmin();
                        frmadmin1.ShowDialog();
                    }
                    else    //操作员登录 
                    {
                        frmMain frmmain1 = new frmMain(this.db1DataSet1.user.Rows[0]["username"].ToString());
                        frmmain1.ShowDialog();
                    }
                    this.Close();
                }
                else
                { MessageBox.Show("用户名或密码有误！"); }
            }
           
        }

        private void frmlogin_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            frmpasschange frmpasschange1 = new frmpasschange();
            frmpasschange1.ShowDialog();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) textBox2.Focus();
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) button1.Focus();
        }
    }
}


/*
 * 如何获得DataSet结果集中的值


DataSet.Tables[0].Rows[n];   
第n行
    
DataSet.Tables[0].Rows[m][n];   
第m行，第n列

DataSet.Tables[0].Rows.Count()
返回行数


ds.Tables["users"].Columns["s_id"].ColumnName

ds.Tables["users"].Rows[0]["s_id"].ColumnName


DataSet ds ;//给ds赋值 

for(int dsR=0;dsR <ds.Tables[0].Rows.Count;dsR++)//行循环 
{ 
for(int dsC=0;dsC <ds.Tables[0].Columns.Count;dsC++)//列循环 
{ 
Response.Write(ds.Tables[0].Rows[dsR][dsC].ToString()+ " ");//几行几列的值 
} 
Response.Write( " <br> ");//换行 
}
*/